home *** CD-ROM | disk | FTP | other *** search
- /*
- Header file for multi thread Macintosh task
-
- You can call CreateQueue to get a pointer to data structure for the queue
-
- You can call all A/ROSE routines through this structure
-
- You can call DestroyQueue to get rid of this structure
-
- Written by: Anumele D. Raja
-
- Date: March 19, 1991
-
- Copyright @ Apple Computer, Inc. 1991
-
- */
-
- #ifndef __TYPES__
- #include <Types.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __MEMORY__
- #include <Memory.h>
- #endif
-
- #ifndef _os_defined_
- #include "os.h"
- #endif
-
- struct QueueEntry {
- Handle rsrcHandle; // Reserved area
- void (*CloseQueue)(void);
- void (*FreeMsg)(mMessage *msgPtr);
- char (*GetCard)(void);
- unsigned long (*GetETick)(void);
- tid_type (*GetICCTID)(void);
- struct IPCg *(*GetIPCg)(void);
- mMessage *(*GetMsg)(void);
- tid_type (*GetNameTID)(void);
- unsigned short (*GetTickPS)(void);
- tid_type (*GetTID)(void);
- short (*IsLocal)(char *address);
- void (*KillReceive)(void);
- short (*LockRealArea)(void *virtualAddr, unsigned long length,
- struct addressareas buffer[], unsigned long count);
- tid_type (*Lookup_Task)(char *object, char *type, tid_type nm_TID,
- unsigned short *index);
- short (*NetCopy)(tid_type srcTID, void *srcAddress,
- tid_type dstTID, void *dstAddress,
- unsigned long byteCount);
- tid_type (*OpenQueue)(void (*UserProcedure)(void));
- mMessage *(*Receive)(unsigned long mID, tid_type mFrom,
- unsigned short mCode, long timeOut,
- void (*CompletionRoutine)(mMessage *));
- char (*Register_Task)(char object[], char type[], short local_only);
- void (*Send)(mMessage *msgPtr);
- void (*SwapTID)(mMessage *msgPtr);
- void (*UnLockRealArea)(void *virtualAddr, unsigned long length);
- };
-
- #ifndef __cplusplus
- typedef struct QueueEntry QueueEntry;
- #endif
-
- // Routine that reads in the MultiThread resource and returns a pointer
-
- /*
- Usage:
-
- In this program you are operating on another queue in addition to the
- queue you get with plain OpenQueue
-
- QueueEntry *queuePtr;
-
- if (queuePtr = CreateQueue()) {
- // Queue is ok
-
- mMessage *mspPtr;
- tid_type myTID;
-
- myTID = queuePtr->OpenQueue();
- msgPtr = quueuePtr->GetMsg();
- .
- .
- .
- queuePtr->Send(msgPtr);
- .
- .
- .
- msgPtr = queuePtr->Receive(OS_MATCH_ALL, myTID, OS_MATCH_ALL, -1, 0);
- .
- .
- .
- DestroyQueue(queuePtr);
- .
- .
- .
- */
-
- const kRsrcType = 'mlti';
- const char kRsrcName[] = "\PMultiThread";
-
- QueueEntry *CreateQueue()
- {
- Handle multiHdl;
- QueueEntry *qPtr;
- void *(*GetPtr)(void);
-
- if ((multiHdl = GetNamedResource(kRsrcType, kRsrcName)) == 0)
- return 0;
-
- DetachResource(multiHdl); // Delink the handle from resource
-
- MoveHHi(multiHdl); // Move it to high memory ready for locking
-
- HLock(multiHdl);
-
- GetPtr = (void *)*multiHdl;
- qPtr = (QueueEntry *)StripAddress(GetPtr());
- qPtr->rsrcHandle = multiHdl; // save the handle
- return qPtr;
- }
-
- void DestroyQueue(QueueEntry *qPtr)
- {
- Handle multiHdl;
-
- multiHdl = qPtr->rsrcHandle;
-
- HUnlock(multiHdl);
- DisposHandle(multiHdl);
- }
-